from pathlib import Path
import sys

# Usage: python rename_remove_last_suffix.py [media_root] [suffix]
# Example: python rename_remove_last_suffix.py add mp4.bak

try:
    media_root = sys.argv[1]
except:
    media_root = 'test'

try:
    old_suffix = sys.argv[2]
except:
    old_suffix = 'mp4.ok'


medias = [str(media) for media in Path(media_root).glob(''.join(['*.',old_suffix]))]
print(''.join(["Total media files:\t",str(len(medias))]))
for media in medias:
    newMediaName = str(Path(media).stem)
    Path(media).rename(''.join([media_root,'/',newMediaName]))
